<?php
  class Ecole{
      
     private $id;
     private $nom;
     private $adresse;
     private $cp;
     private $ville;
     private $nb_eleve;
     private $nom_directeur;
     private $mail;
     private $tel;
     private $fax;
     private $cycle1;
     private $cycle2;
     private $cycle3;
     private $priv_pub;
     private $id_vente;
     private $statut;
     
     public function __construct($id_ecole){
        $db = new Db();
        $req = $db->query("SELECT * FROM ecole WHERE id_ecole='".$id_ecole."';");
        $res = mysql_fetch_object($req);
        $this->id=$res->id_ecole;
        $this->nom = $res->nom_ecole;
        $this->adresse = $res->adresse_ecole;
        $this->cp = $res->cp_ecole;
        $this->ville = $res->ville_ecole;
        $this->nb_eleve = $res->nb_eleve_ecole;
        $this->nom_directeur = $res->nom_directeur_ecole;
        $this->mail = $res->mail_ecole;
        $this->tel = $res->tel_ecole;
        $this->fax = $res->fax_ecole;
        $this->cycle1 = $res->cycle1_ecole;
        $this->cycle2 = $res->cycle2_ecole;
        $this->cycle3 = $res->cycle3_ecole;
        $this->priv_pub = $res->pub_priv_ecole;
        $this->valide = $res->valide;
        $this->statut = $res->statut;
        
        $req = $db->query("SELECT id_vente FROM vente v,ecole e WHERE v.id_ecole = e.id_ecole AND e.id_ecole='".$id_ecole."';");
        $res = mysql_fetch_object($req);
        
        $this->id_vente = $res->id_vente;
     }
        // Getters
        
     public function get_id(){
        return $this->id;
     }
     
     public function get_statut(){
        return $this->statut;
     }
               
     public function est_publique(){ // Retourne vrai si l'école est publique
        return $this->priv_pub=="pub";
     }
     
     public function changer_statut($statut){
        $db = new Db();
        $req = $db->query("UPDATE ecole SET statut = '$statut' WHERE id_ecole='".$this->get_id()."';");
     }   
     
     public function get_nom(){
        return utf8_encode($this->nom);
     }
     
     public function get_adresse(){
        return utf8_encode($this->adresse);
     }
     
     public function get_cp(){
        return $this->cp;
     }
     
     public function get_ville(){
        return utf8_encode($this->ville);
     }
     
     public function  get_nb_eleve(){
         return $this->nb_eleve;
     }
     
     public function get_nom_directeur(){
         return utf8_encode($this->nom_directeur);
     }
     
     public function get_mail(){
         return utf8_encode($this->mail);
     }
     
     public function get_tel(){
         return $this->tel;
     }
     
     public function get_fax(){
         return $this->fax;
     }
      
     
     public function get_donnation(){
         if($this->id_donnation!=null)
            return $this->id_donnation;
         else
            return false;
     }
     
     public function get_id_vente(){
        return $this->id_vente;
     }

      // Méthodes 
      
     public function get_cycles(){
        if($this->cycle1==1)
            $cycle[1]=true;
        else
            $cycle[1]=false;

        if($this->cycle2==1)
            $cycle[2]=true;
        else
            $cycle[2]=false;
            
        if($this->cycle3==1)
            $cycle[3]=true;
        else
            $cycle[3]=false;
            
        return $cycle;
     }
}
?>
